package com.lyf.boot.runner;

import cn.hutool.core.collection.CollUtil;
import com.lyf.boot.modules.system.service.IOssConfigService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.dromara.sms4j.core.datainterface.SmsReadConfig;
import org.dromara.sms4j.core.factory.SmsFactory;
import org.dromara.sms4j.provider.config.BaseConfig;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author Luyufan
 * @date 2023/7/7 17:48
 */
@Slf4j
@RequiredArgsConstructor
@Component
public class SystemApplication implements ApplicationRunner {

    private final IOssConfigService ossConfigService;

    private final SmsReadConfig smsReadConfig;

    @Override
    public void run(ApplicationArguments args) {
        ossConfigService.initOssConfig();
        log.debug("oss对象存储注入成功");
        SmsFactory.createSmsBlend(smsReadConfig.getSupplierConfig("jwjs"));
        List<BaseConfig> smsConfigs = smsReadConfig.getSupplierConfigList();
        if(CollUtil.isNotEmpty(smsConfigs)){
            smsConfigs.forEach(config -> {
                SmsFactory.createSmsBlend(config);
                log.debug("短信配置注入成功:{}", config.getConfigId());
            });
        }

    }
}
